<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import type { ComponentSize } from 'element-plus'
import { adminApplyStore, authStore, refuseStore } from '../assets/net/NetUtils';
import { StoreModel } from '../assets/model/Store';


const fill = ref<boolean>(true)
const size = ref<ComponentSize>('default')
const stores = ref<Array<StoreModel>>()
let isEmpty = ref(true)
onMounted(() => {
    adminApplyStore()
        .then((value) => {
            stores.value = value.data;
            isEmpty.value = value.data.length === 0 ? true : false;
        })
})

const authStoreClick = (id: number) => {
    authStore(id)
        .then(() => {
            adminApplyStore()
                .then((value) => {
                    stores.value = value.data;
                    isEmpty.value = value.data.length === 0 ? true : false;
                })
        })
}

const refuseStoreClick = (id: number) => {
    refuseStore(id)
        .then(() => {
            adminApplyStore()
                .then((value) => {
                    stores.value = value.data;
                    isEmpty.value = value.data.length === 0 ? true : false;
                })
        })
}
</script>

<template>
    <el-scrollbar height="100%" style="overflow-y: hidden;">
        <el-empty v-show="isEmpty" style="width: 100%;height: 100%;" description="这里还没有待审核的商铺哦～" />
        <el-space wrap :size="size" :fill="fill" style="width: 100%;">
            <div v-for="i in stores" :key="i.sid">
                <el-card shadow="hover" style="height: auto;">
                    <el-row style="width: 100%;" align="middel">
                        <el-col :span="20">
                            <el-row>
                                <el-col :span="24">
                                    <el-text style="font-size: large;font-weight: bold;">
                                        {{ i.name }}
                                    </el-text>
                                </el-col>
                                <el-col :span="24" style="margin-top: 1%;">
                                    <el-text>
                                        申请人：{{ i.user.username }}
                                    </el-text>
                                </el-col>
                                <el-col :span="24" style="margin-top: 1%;">
                                    <el-text>
                                        店铺描述：{{ i.description }}
                                    </el-text>
                                </el-col>
                            </el-row>
                        </el-col>
                        <el-col :span="4">
                            <el-row>
                                <el-col :span="24">
                                    <el-button type="danger" plain style="width: 100%;padding: 3%;"
                                        @click="refuseStoreClick(i.sid)">驳回申请</el-button>
                                </el-col>
                                <el-col :span="24" style="margin-top: 10%;">
                                    <el-button type="success" plain style="width: 100%;padding: 3%;"
                                        @click="authStoreClick(i.sid)">同 意</el-button>
                                </el-col>
                            </el-row>
                        </el-col>
                    </el-row>
                </el-card>
            </div>
        </el-space>
    </el-scrollbar>
</template>